<?php

/**
 * xxs过滤
 * @param $data
 * @return mixed
 */
function removeXss($data) {
    require_once 'HtmlPurifier/HTMLPurifier.auto.php';
    $_clean_xss_config = HTMLPurifier_Config::createDefault();
    $_clean_xss_config->set('Core.Encoding', 'UTF-8');
    $_clean_xss_config->set('HTML.Allowed', 'div,b,strong,i,em,a[href|title],ul,ol,li,p[style],br,span[style],img[width|height|alt|src]');
    $_clean_xss_config->set('CSS.AllowedProperties', 'font,font-size,font-weight,font-style,font-family,text-decoration,padding-left,color,background-color,text-align');
    $_clean_xss_config->set('HTML.TargetBlank', TRUE);
    $_clean_xss_obj = new HTMLPurifier($_clean_xss_config);
    //执行过滤
    return $_clean_xss_obj->purify($data);
}
/**
 * 显示图片
 * @param $url
 * @param string $width
 * @param string $height
 */
function showImage($url, $width = '', $height = '',$style='',$title='')
{
    $ic = C('IMAGE_CONFIG');
    if($width)
        $width = "width:'$width'";
    if($height)
        $height = "height:'$height'";
    if($style)
        $style = "class='$style'";
    if($title){
        $title= "title='$title'";
    }
    echo "<img $width $height $style $title src='{$ic['viewPath']}$url' />";
}

/**
 * 制作下拉框
 * @param $tableName
 * @param $selectname
 * @param $valueFieldName
 * @param $textFieldName
 * @param string $selectValue  <?php buildSelect('course','course_id','id','course_name'); ?>
 */
if(!function_exists('buildSelect')){
    function  buildSelect($tableName,$selectname,$valueFieldName,$textFieldName,$selectValue=''){   //表名，下拉选框的名字，循环的Id，循环的名称，要选择的字段的值
        $model = D($tableName);
        if(session('admin.company_id') == 1){
            $data = $model->field("$valueFieldName,$textFieldName")->select();
        }else{
            $data = $model->field("$valueFieldName,$textFieldName")->where(['company_id'=>['eq',session('admin.company_id')]])->select();
        }
        $select = "<select class=\"form-control input-sm\"  name ='$selectname'> <option value=''>请选择&nbsp;&nbsp;&nbsp;&nbsp;</option>";
//    dump($data);
        foreach($data as $k => $v){
            $value = $v[$valueFieldName];   //id循环的id
//        dump($value);
            $text = $v[$textFieldName];    //id对应的名称
            if($selectValue && $selectValue ==$value ){   //$selectValue为商品Id
                $selected = 'selected ="selected"';
            }else{
                $selected ='';
            }
            $select .= '<option ' .$selected. 'value="' .$value.'">'.$text. '</option>';
//        dump($select);
        }
        $select .= '<option value="" disabled></option>';
        $select .= '</select>';
//    dump($selected);
        echo $select;
    }
}

/**
 * 上传一张图片
 * @param $imgName
 * @param $dirName  注意大写
 * @param array $thumb
 * @return array
 */
function uploadOne($imgName, $dirName, $thumb = array())
{
        // 上传LOGO
        if(isset($_FILES[$imgName]) && $_FILES[$imgName]['error'] == 0)
        {
            $ic = C('IMAGE_CONFIG');
            $upload = new \Think\Upload(array(
                'rootPath' => $ic['rootPath'],
                'maxSize' => $ic['maxSize'],
                'exts' => $ic['exts'],
            ));// 实例化上传类
            $upload->savePath = $dirName . '/'; // 图片二级目录的名称
            // 上传文件
            // 上传时指定一个要上传的图片的名称，否则会把表单中所有的图片都处理，之后再想其他图片时就再找不到图片了
            $info   =   $upload->upload(array($imgName=>$_FILES[$imgName]));
            if(!$info)
            {
                return array(
                    'ok' => 0,
                    'error' => $upload->getError(),
                );
            }
            else
            {
                $ret['ok'] = 1;
                $ret['images'][0] = $logoName = $info[$imgName]['savepath'] . $info[$imgName]['savename'];
                // 判断是否生成缩略图
                if($thumb)
                {
                    $image = new \Think\Image();
                    // 循环生成缩略图
                    foreach ($thumb as $k => $v)
                    {
                        $ret['images'][$k+1] = $info[$imgName]['savepath'] . 'thumb_'.$k.'_' .$info[$imgName]['savename'];
                        // 打开要处理的图片
                        $image->open($ic['rootPath'].$logoName);
                        $image->thumb($v[0], $v[1])->save($ic['rootPath'].$ret['images'][$k+1]);
                    }
                }
                return $ret;
            }
        }

}
function uploadFile($fileName,$dirName){
    if(isset($_FILES[$fileName]) && $_FILES[$fileName]['error'] == 0){
         $fc = C('file_config');
        $upload = new \Think\Upload(array(
            'rootPath' => $fc['rootPath'],
            'maxSize' => $fc['maxSize'],
            'exts' => $fc['exts'],
        ));// 实例化上传类
        $upload->savePath = $dirName . '/'; // 文件二级目录的名称
        // 上传文件
        // 上传时指定一个要上传的文件的名称
        $info   =   $upload->uploadOne($_FILES[$fileName]);
        if(!$info) {// 上传错误提示错误信息
            return $this->error($upload->getError());
        }else{// 上传成功 获取上传文件信息

            return $info['savepath'].$info['savename'];
        }
    }
}

/**删除图片
 * @param array $iamge
 */
function deleteImage($iamge=array()){
    $savePath=C('IMAGE_SAVE_PATH');
    foreach($iamge as $v){
        unlink($savePath.$v);
    }
}
function catGetArticle($catName)
{
    //获取分类ID
    $catModel = D('Admin/Category');
    $catId = $catModel->field('id')
        ->where([
            'name' =>['eq',$catName]
        ])->find();
    //获取文章列表
    if($catId){
        $articleModel = D('Admin/Article');
        $articleListData = $articleModel->field('id,title,create_time,pic')
            ->where([
                'cat_id' => ['in',$catId]
            ])->limit('10')
            ->order('create_time desc')
            ->select();
        return $articleListData;
    }else{
        return null;
    }
}

if(! function_exists('getIdByName')){

    /**
     * @name
     * @desc   <?php getIdByName('admin',$v['admin_id'],'adminname'); ?>
     * @auther ycp
     * @param $table 表名
     * @param $id
     * @param $name 要查询的字段
     */
    function getIdByName($table, $id, $name){
        if($id >0){
            $data = D($table)
                ->where([
                    'id' =>['eq',$id]
                ])->getField($name);
            echo $data;
        }else
            echo '';
    }
}
/**
 * @name
 * @desc
 * @auther ycp
 */
if(! function_exists('generateCode')){
    function generateCode(){
        $code = date('Ymd',time()).substr(time(),-4);
        return $code;
    }
}
/**
 * @name 获取首页导航菜单
 * @desc
 * @auther ycp
 */
if(! function_exists('get_nav')){
    function get_nav(){
        $model = D('Admin/Nav');
        $data = $model->select();
        return $data;
    }
}

/**
*根据传过的data 获取当前星期几
*
*/
function getcnweek($date)
{
    // var_dump($date);
  //强制转换日期格式
       $date_str=date('Y-m-d',strtotime($date));
// var_dump($date_str);
       //封装成数组
       $arr=explode("-", $date_str);

       //参数赋值
       //年
       $year=$arr[0];

       //月，输出2位整型，不够2位右对齐
       $month=sprintf('%02d',$arr[1]);

       //日，输出2位整型，不够2位右对齐
       $day=sprintf('%02d',$arr[2]);

       //时分秒默认赋值为0；
       $hour = $minute = $second = 0;

       //转换成时间戳
       $strap = mktime($hour,$minute,$second,$month,$day,$year);

       //获取数字型星期几
       $number_wk=date("w",$strap);

       //自定义星期数组
       $weekArr=array("星期日","星期一","星期二","星期三","星期四","星期五","星期六");

       //获取数字对应的星期
       return $weekArr[$number_wk];
}


function mintime($starttime,$endtime)
{

  $st = strtotime($starttime);
  $et = strtotime($endtime);

  return number_format(($et-$st)/60);
  # code...
}

//获取老师名称
function getteacher($value)
{
  return M("teacher")->where(array("id"=>$value))->getField('teacher_name');
}

//获取整周参数
function getallweek($time,$num="1")
{
  //自定义星期数组

  $weekArr=array("周日","周一","周二","周三","周四","周五","周六");
  $tt = date("w",strtotime($time));
  switch ($tt) {
    case '0':

    $arr[1]['time'] = date("m-d",strtotime($time)-(6*86400));
    $arr[1]['chw']  =  $weekArr[date("w",strtotime($time)-(6*86400))];


    $arr[2]['time'] = date("m-d",strtotime($time)-(5*86400));
    $arr[2]['chw']  =  $weekArr[date("w",strtotime($time)-(5*86400))];

    $arr[3]['time'] = date("m-d",strtotime($time)-(4*86400));
    $arr[3]['chw']  =  $weekArr[date("w",strtotime($time)-(4*86400))];

    $arr[4]['time'] = date("m-d",strtotime($time)-(3*86400));
    $arr[4]['chw']  =  $weekArr[date("w",strtotime($time)-(3*86400))];

    $arr[5]['time'] = date("m-d",strtotime($time)-(2*86400));
    $arr[5]['chw']  =  $weekArr[date("w",strtotime($time)-(2*86400))];

    $arr[6]['time'] = date("m-d",strtotime($time)-(1*86400));
    $arr[6]['chw']  =  $weekArr[date("w",strtotime($time)-(1*86400))];

    $arr[7]['time'] = date("m-d",strtotime($time)-($tt*86400));
    $arr[7]['chw']  =  $weekArr[date("w",strtotime($time)-($tt*86400))];

    $arr[1]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(6*86400))."%'";
    $arr[2]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(5*86400))."%'";
    $arr[3]['str']  = " and course_date like '%".date("Y-m-d",strtotime($time)-(4*86400))."%'";
    $arr[4]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(3*86400))."%'";
    $arr[5]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(2*86400))."%'";
    $arr[6]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(1*86400))."%'";
    $arr[7]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(0*86400))."%'";
      break;
    case '1':

    $arr[1]['time'] = date("m-d",strtotime($time));
    $arr[1]['chw']  =  $weekArr[date("w",strtotime($time))];

    $arr[2]['time'] = date("m-d",strtotime($time)+(1*86400));
    $arr[2]['chw']  =  $weekArr[date("w",strtotime($time)+(1*86400))];

    $arr[3]['time'] = date("m-d",strtotime($time)+(2*86400));
    $arr[3]['chw']  =  $weekArr[date("w",strtotime($time)+(2*86400))];

    $arr[4]['time'] = date("m-d",strtotime($time)+(3*86400));
    $arr[4]['chw']  =  $weekArr[date("w",strtotime($time)+(3*86400))];

    $arr[5]['time'] = date("m-d",strtotime($time)+(4*86400));
    $arr[5]['chw']  =  $weekArr[date("w",strtotime($time)+(4*86400))];

    $arr[6]['time'] = date("m-d",strtotime($time)+(5*86400));
    $arr[6]['chw']  =  $weekArr[date("w",strtotime($time)+(5*86400))];

    $arr[7]['time'] = date("m-d",strtotime($time)+(6*86400));
    $arr[7]['chw']  =  $weekArr[date("w",strtotime($time)+(6*86400))];

    $arr[1]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(0*86400))."%'";
    $arr[2]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(1*86400))."%'";
    $arr[3]['str']  = " and course_date like '%".date("Y-m-d",strtotime($time)+(2*86400))."%'";
    $arr[4]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(3*86400))."%'";
    $arr[5]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(4*86400))."%'";
    $arr[6]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(5*86400))."%'";
    $arr[7]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(6*86400))."%'";
      break;
    case '2':
    $arr[1]['time'] = date("m-d",strtotime($time)-86400);
    $arr[1]['chw']  =  $weekArr[date("w",strtotime($time)-86400)];

    $arr[2]['time'] = date("m-d",strtotime($time));
    $arr[2]['chw']  =  $weekArr[date("w",strtotime($time))];

    $arr[3]['time'] = date("m-d",strtotime($time)+(1*86400));
    $arr[3]['chw']  =  $weekArr[date("w",strtotime($time)+(1*86400))];

    $arr[4]['time'] = date("m-d",strtotime($time)+(2*86400));
    $arr[4]['chw']  =  $weekArr[date("w",strtotime($time)+(2*86400))];

    $arr[5]['time'] = date("m-d",strtotime($time)+(3*86400));
    $arr[5]['chw']  =  $weekArr[date("w",strtotime($time)+(3*86400))];

    $arr[6]['time'] = date("m-d",strtotime($time)+(4*86400));
    $arr[6]['chw']  =  $weekArr[date("w",strtotime($time)+(4*86400))];

    $arr[7]['time'] = date("m-d",strtotime($time)+(5*86400));
    $arr[7]['chw']  =  $weekArr[date("w",strtotime($time)+(5*86400))];

    $arr[1]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(1*86400))."%'";
    $arr[2]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(0*86400))."%'";
    $arr[3]['str']  = " and course_date like '%".date("Y-m-d",strtotime($time)+(1*86400))."%'";
    $arr[4]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(2*86400))."%'";
    $arr[5]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(3*86400))."%'";
    $arr[6]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(4*86400))."%'";
    $arr[7]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(5*86400))."%'";
      break;
    case '3':
    $arr[1]['time'] = date("m-d",strtotime($time)-(2*86400));
    $arr[1]['chw']  =  $weekArr[date("w",strtotime($time)-(2*86400))];

    $arr[2]['time'] = date("m-d",strtotime($time)-(1*86400));
    $arr[2]['chw']  =  $weekArr[date("w",strtotime($time)-(1*86400))];

    $arr[3]['time'] = date("m-d",strtotime($time)+(0*86400));
    $arr[3]['chw']  =  $weekArr[date("w",strtotime($time)+(0*86400))];

    $arr[4]['time'] = date("m-d",strtotime($time)+(1*86400));
    $arr[4]['chw']  =  $weekArr[date("w",strtotime($time)+(1*86400))];

    $arr[5]['time'] = date("m-d",strtotime($time)+(2*86400));
    $arr[5]['chw']  =  $weekArr[date("w",strtotime($time)+(2*86400))];

    $arr[6]['time'] = date("m-d",strtotime($time)+(3*86400));
    $arr[6]['chw']  =  $weekArr[date("w",strtotime($time)+(3*86400))];

    $arr[7]['time'] = date("m-d",strtotime($time)+(4*86400));
    $arr[7]['chw']  =  $weekArr[date("w",strtotime($time)+(4*86400))];

    $arr[1]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(2*86400))."%'";
    $arr[2]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(1*86400))."%'";
    $arr[3]['str']  = " and course_date like '%".date("Y-m-d",strtotime($time)+(0*86400))."%'";
    $arr[4]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(1*86400))."%'";
    $arr[5]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(2*86400))."%'";
    $arr[6]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(3*86400))."%'";
    $arr[7]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(4*86400))."%'";
      break;
    case '4':
    $arr[1]['time'] = date("m-d",strtotime($time)-(3*86400));
    $arr[1]['chw']  =  $weekArr[date("w",strtotime($time)-(3*86400))];

    $arr[2]['time'] = date("m-d",strtotime($time)-(2*86400));
    $arr[2]['chw']  =  $weekArr[date("w",strtotime($time)-(2*86400))];

    $arr[3]['time'] = date("m-d",strtotime($time)-(1*86400));
    $arr[3]['chw']  =  $weekArr[date("w",strtotime($time)-(1*86400))];

    $arr[4]['time'] = date("m-d",strtotime($time)+(0*86400));
    $arr[4]['chw']  =  $weekArr[date("w",strtotime($time)+(0*86400))];

    $arr[5]['time'] = date("m-d",strtotime($time)+(1*86400));
    $arr[5]['chw']  =  $weekArr[date("w",strtotime($time)+(1*86400))];

    $arr[6]['time'] = date("m-d",strtotime($time)+(2*86400));
    $arr[6]['chw']  =  $weekArr[date("w",strtotime($time)+(2*86400))];

    $arr[7]['time'] = date("m-d",strtotime($time)+(3*86400));
    $arr[7]['chw']  =  $weekArr[date("w",strtotime($time)+(3*86400))];

    $arr[1]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(3*86400))."%'";
    $arr[2]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(2*86400))."%'";
    $arr[3]['str']  = " and course_date like '%".date("Y-m-d",strtotime($time)-(1*86400))."%'";
    $arr[4]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(0*86400))."%'";
    $arr[5]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(1*86400))."%'";
    $arr[6]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(2*86400))."%'";
    $arr[7]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(3*86400))."%'";
      break;
    case '5':
    $arr[1]['time'] = date("m-d",strtotime($time)-(4*86400));
    $arr[1]['chw']  =  $weekArr[date("w",strtotime($time)-(4*86400))];

    $arr[2]['time'] = date("m-d",strtotime($time)-(3*86400));
    $arr[2]['chw']  =  $weekArr[date("w",strtotime($time)-(3*86400))];

    $arr[3]['time'] = date("m-d",strtotime($time)-(2*86400));
    $arr[3]['chw']  =  $weekArr[date("w",strtotime($time)-(2*86400))];

    $arr[4]['time'] = date("m-d",strtotime($time)-(1*86400));
    $arr[4]['chw']  =  $weekArr[date("w",strtotime($time)-(1*86400))];

    $arr[5]['time'] = date("m-d",strtotime($time)+(0*86400));
    $arr[5]['chw']  =  $weekArr[date("w",strtotime($time)+(0*86400))];

    $arr[6]['time'] = date("m-d",strtotime($time)+(1*86400));
    $arr[6]['chw']  =  $weekArr[date("w",strtotime($time)+(1*86400))];

    $arr[7]['time'] = date("m-d",strtotime($time)+(2*86400));
    $arr[7]['chw']  =  $weekArr[date("w",strtotime($time)+(2*86400))];

    $arr[1]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(4*86400))."%'";
    $arr[2]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(3*86400))."%'";
    $arr[3]['str']  = " and course_date like '%".date("Y-m-d",strtotime($time)-(2*86400))."%'";
    $arr[4]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(1*86400))."%'";
    $arr[5]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(0*86400))."%'";
    $arr[6]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(1*86400))."%'";
    $arr[7]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(2*86400))."%'";


      break;
    case '6':

    $arr[1]['time'] = date("m-d",strtotime($time)-(5*86400));
    $arr[1]['chw']  =  $weekArr[date("w",strtotime($time)-(5*86400))];

    $arr[2]['time'] = date("m-d",strtotime($time)-(4*86400));
    $arr[2]['chw']  =  $weekArr[date("w",strtotime($time)-(4*86400))];

    $arr[3]['time'] = date("m-d",strtotime($time)-(3*86400));
    $arr[3]['chw']  =  $weekArr[date("w",strtotime($time)-(3*86400))];

    $arr[4]['time'] = date("m-d",strtotime($time)-(2*86400));
    $arr[4]['chw']  =  $weekArr[date("w",strtotime($time)-(2*86400))];

    $arr[5]['time'] = date("m-d",strtotime($time)-(1*86400));
    $arr[5]['chw']  =  $weekArr[date("w",strtotime($time)-(1*86400))];

    $arr[6]['time'] = date("m-d",strtotime($time)+(0*86400));
    $arr[6]['chw']  =  $weekArr[date("w",strtotime($time)+(0*86400))];

    $arr[7]['time'] = date("m-d",strtotime($time)+(1*86400));
    $arr[7]['chw']  =  $weekArr[date("w",strtotime($time)+(1*86400))];

    $arr[1]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(5*86400))."%'";
    $arr[2]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(3*86400))."%'";
    $arr[3]['str']  = " and course_date like '%".date("Y-m-d",strtotime($time)-(3*86400))."%'";
    $arr[4]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(2*86400))."%'";
    $arr[5]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)-(1*86400))."%'";
    $arr[6]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(0*86400))."%'";
    $arr[7]['str'] = " and course_date like '%".date("Y-m-d",strtotime($time)+(1*86400))."%'";
    
      break;
    default:
      # code...
      break;
  }

  return $arr;


}

function getcoursename($id)
{
  return M("course")->where(array("id"=>$id))->getField('course_name');
}
//获取教室名称
function getClassroom($id)
{
  return M("classroom")->where(array("id"=>$id))->getField('classroom_name');
}

//获取剩余courser 数量
function get_sy_class($id)
{
  $num = M('CourseCalendar')->where(array("course_id"=>$id))->getField('limit_num');
  $dnum = M("yuyue")->where(array("course_id"=>$id))->count();
  return $num-$dnum;
}

/**
 * 规则读取
 * @param $uid 会员的id
 * @param $class_id 选择课程的id
 * @return true 该课程存在于不能预定的课程  false 该课程不存在于不能预定的课程
 */

function getcheckcardguize($uid,$class_id="")
{
    $res = M("member")->field("card_id,company_id")->where(array("id"=>$uid))->find();

    $res['id'] = $res['card_id'];
    $res['company_id'] = $res['company_id'];
    unset($res['card_id']);
    $resclass = M("card")->where($res)->getField("noclass");

    if($resclass)
    {
        $resarr = json_decode($resclass);
        if(in_array($class_id,$resarr))
        {
            return true;
        }else
        {
            return false;
        }
    }else
    {
        return false;
    }
}

/**
 * @param $uid 用户id
 * @param $mobile 散客
 * @param $company_id 当前公司 company_id
 */
function getsetcardguize($uid="",$mobile="",$company_id)
{
    $where['id'] = $uid;

    $res = M('member')->where($where)->find();

    unset($where['id']);
    $where['card_id'] = $res['card_id'];
    $cardguize = M('CardGuize')->where($where)->find();
    if($cardguize)
    {
        if($cardguize['cancross']=='YES')
        {
            if($cardguize['company_id']!=$company_id)
            {
                $data['status'] = '2';
                $data['info'] = '不可再其他分店使用';
            }
        }

        if($cardguize['dateoddeven'])
        {
            $today = date("w",time());
            if($cardguize['dateoddeven']=='odd')
            {
                if(in_array($today,array("2","4","6")))
                {
                    $data['status'] = '2';
                    $data['info'] = "今天不可预约";
                }
            }else
            {
                if(in_array($today,array("0","1","3","5")))
                {
                    $data['status'] = '2';

                    $data['info'] = "今天不可预约";
                }
            }
        }

        if($cardguize['timezone'])
        {
            $arrtime = json_decode($cardguize['timezone']);
            $starttime = strtotime(date("Y-m-d ").$arrtime['0']);
            $endtime = strtotime(date("Y-m-d ").$arrtime['1']);
            if($starttime>time() || $endtime<time())
            {
                $data['status'] = '2';
                $data['info'] = "已超出时间，不可预约";
            }
        }

        if($cardguize['weekday'])
        {
            $today = date("w",time());
            if($today=='0')$today='1';
            $weekday = json_decode($cardguize['weekday']);
            if(!in_array($today,$weekday))
            {
                $data['status'] = '2';
                $data['info'] = "该卡今日不可预约";
            }

        }

        if($cardguize['weektimes'])
        {
            $restime = getallweek(date("Y-m-d",time()));

            $count=0;
            foreach ($restime as $v)
            {
                $sql = str_replace("start_time","yueyu_time",$v['str']);
                if($res['telphone']=="")
                {
                    $res['telphone'] = $mobile;
                }
                $weektime = " yueyu_tel ='".$res['telphone']."'".$sql;

                $count +=M('yuyue')->where($weektime)->count();

            }
            if($count>$cardguize['weektimes'])
            {
                $data['status'] = '2';
                $data['info'] = "已超过每周最大预约次数";
            }
        }

        if($cardguize['daytimes'])
        {
            if($res['telphone']=="")
            {
                $res['telphone'] = $mobile;
            }
            $weektime = " yueyu_tel ='".$res['telphone']."' and yueyu_time like '%".date("Y-m-d",time())."%'";


            $countday =M('yuyue')->where($weektime)->count();
            if($countday>$cardguize['daytimes'])
            {
                $data['status'] = '2';
                $data['info'] = "已超过每日最大预约次数";
            }
        }
    }else
    {
        $data['status'] = '3';
        $data['info'] = '该卡项没有设置规则';
    }


    return $data;
}